package controller;

import model.Users;
import dao.travellerTeamDao;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;

public class travellerTeamController extends HttpServlet{
    public   travellerTeamController(){
        super();
    }
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        travellerTeamDao team = new travellerTeamDao();

        Users user = (Users)request.getSession().getAttribute("users");
        if(user == null){
            request.setAttribute("error","please login");
            request.setAttribute("name",request.getParameter("location"));
            request.getRequestDispatcher("/travellerTeamIndex.jsp").forward(request,response);
        }
        else{
            try {
                String city = request.getParameter("location");
                team.insetCity(city,user.getIdusers());
                request.setAttribute("error","succeed");
                request.setAttribute("name",request.getParameter("location"));
                request.getRequestDispatcher("/travellerTeamIndex.jsp").forward(request,response);
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
